package com.common.util;

import com.common.service.CommonService;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.lang.NonNull;

/**
 * Date 2018/07/05
 *
 * @author MT-Lin
 */
@SuppressWarnings("ALL")
public class MainTestUtil {

    public static void outResponse(String projectName, String dubboConfigFileName, BaseMainTestClass mainTestClass) throws InterruptedException {
        mainTestClass.setLogger();
        System.setProperty("java.net.preferIPv4Stack", "true");
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
                new String[]{"META-INF/spring/" + dubboConfigFileName});
        context.start();
        // 获取远程服务代理
        CommonService commonService = context.getBean(CommonService.class);
        // 执行远程方法并返回结果
        while (true) {
            Thread.sleep(1000);
            // 执行远程方法
            String response =  commonService.getFromWhere(projectName, mainTestClass.getClass().getName());
            // 显示调用结果
            mainTestClass.getLogger().info(response);
        }
    }
}
